package org.liuyuantao.patterns.strategy;


import org.liuyuantao.patterns.strategy.duck.Duck;
import org.liuyuantao.patterns.strategy.duck.GreenHeadDuck;
import org.liuyuantao.patterns.strategy.duck.RedHeadDuck;
import org.liuyuantao.patterns.strategy.flybehavior.GoodFlyBehavior;
import org.liuyuantao.patterns.strategy.flybehavior.NoFlyBehavior;
import org.liuyuantao.patterns.strategy.quackbehavior.GaGaQuackBehavior;
import org.liuyuantao.patterns.strategy.quackbehavior.NoQuackBehavior;

/**
 * 策略设计模式,将程序中变化的部分和不变的部分分开
 * 变成的部分封装成接口,不变的部分封装在父类
 * 通过组合的方式来实现
 */
public class StimulateDuck {

    public static void main(String[] args) {
        Duck mGreenHeadDuck = new GreenHeadDuck(new GoodFlyBehavior(), new GaGaQuackBehavior());
        Duck mRedHeadDuck = new RedHeadDuck(new GoodFlyBehavior(), new GaGaQuackBehavior());

        mGreenHeadDuck.display();
        mGreenHeadDuck.Fly();
        mGreenHeadDuck.Quack();
        mGreenHeadDuck.swim();

        mRedHeadDuck.display();
        mRedHeadDuck.Fly();
        mRedHeadDuck.Quack();
        mRedHeadDuck.swim();
        mRedHeadDuck.display();
        mRedHeadDuck.SetFlyBehavoir(new NoFlyBehavior());
        mRedHeadDuck.Fly();
        mRedHeadDuck.SetQuackBehavoir(new NoQuackBehavior());
        mRedHeadDuck.Quack();
    }

}
